<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<html>
<head>
    <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
</head>
<body>
<div>
    <a href="/login.jsp">login</a>
    <sec:authorize ifNotGranted="ROLE_ANONYMOUS">
        <a href="<spring:url value="/j_spring_security_logout" htmlEscape="true" />">Logout</a>
    </sec:authorize>
</div>
<c:forEach items="${coupons}" var="coupon">
    <div style="border: 1px solid #cccccc; width: 300px;position: relative; float: left; display: block;">
        <table>
            <tr>
                <td><img src="http://www.discovergoodwill.com/Coupon9.jpg" width="100px" height="100px"/></td>
                <td>${coupon.title}<br/>
                    Initial price: ${coupon.initialPrice}<br/>
                    Discounted price: ${coupon.discountedPrice}<br/>
                    Discount percent: ${coupon.discountPercent}%<br/>
                    <sec:authorize ifNotGranted="ROLE_ANONYMOUS">
                        <input type="checkbox" class="clipCoupon" value="${coupon.clipped}"/>
                    </sec:authorize>
                    <input type="hidden" id="couponId" value="${coupon.id}"/>
                </td>

            </tr>
        </table>
    </div>
</c:forEach>
<script type="text/javascript">
    $(document).ready(function () {
        $(".clipCoupon").change(function () {
            var id = $(this).parent().children("#couponId").val();
            $.post("addToCart", id, function (data) {
                if (data == "success") {
                }
            });
            return false;


        })
    })
</script>
</body>
</html>
